package com.ruoyi.project.modules.tableObject.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.modules.tableObject.domain.TableObject;
import com.ruoyi.project.modules.tableObject.service.ITableObjectService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 对象关系Controller
 * 
 * @author smallrain
 * @date 2021-11-06
 */
@Controller
@RequestMapping("/tableObject/tableObject")
public class TableObjectController extends BaseController
{
    private String prefix = "tableObject/tableObject";

    @Autowired
    private ITableObjectService tableObjectService;

    @RequiresPermissions("tableObject:tableObject:view")
    @GetMapping()
    public String tableObject()
    {
        return prefix + "/tableObject";
    }

    /**
     * 查询对象关系列表
     */
    @RequiresPermissions("tableObject:tableObject:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TableObject tableObject)
    {
        startPage();
        List<TableObject> list = tableObjectService.selectTableObjectList(tableObject);
        return getDataTable(list);
    }

    /**
     * 导出对象关系列表
     */
    @RequiresPermissions("tableObject:tableObject:export")
    @Log(title = "对象关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TableObject tableObject)
    {
        List<TableObject> list = tableObjectService.selectTableObjectList(tableObject);
        ExcelUtil<TableObject> util = new ExcelUtil<TableObject>(TableObject.class);
        return util.exportExcel(list, "对象关系数据");
    }

    /**
     * 新增对象关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存对象关系
     */
    @RequiresPermissions("tableObject:tableObject:add")
    @Log(title = "对象关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TableObject tableObject)
    {
        return toAjax(tableObjectService.insertTableObject(tableObject));
    }

    /**
     * 修改对象关系
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TableObject tableObject = tableObjectService.selectTableObjectById(id);
        mmap.put("tableObject", tableObject);
        return prefix + "/edit";
    }

    /**
     * 修改保存对象关系
     */
    @RequiresPermissions("tableObject:tableObject:edit")
    @Log(title = "对象关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TableObject tableObject)
    {
        return toAjax(tableObjectService.updateTableObject(tableObject));
    }

    /**
     * 删除对象关系
     */
    @RequiresPermissions("tableObject:tableObject:remove")
    @Log(title = "对象关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tableObjectService.deleteTableObjectByIds(ids));
    }
}
